import 'package:winkai/db/dao/msg_dao.dart';

import '../db/database.dart';
import '../entity/msg_constant.dart';
import '../entity/mse_rpy_rsp.dart';

abstract class MsgService {
  ///查询消息
  Future<List<MsgInfo>> getMsgList(String sessionId,
      {bool isAsc = true, int? limit, int? offset}) {
    return rootDb.msgDao.selectBySessionId(sessionId,
        isAsc: isAsc, limit: limit, offset: offset);
  }

  /// 发送消息
  /// [content] 消息内容
  /// [messageId] 消息id，仅重发场景使用
  /// [sessionId] 会话id
  /// [lastServiceMessageId] 服务端的消息ID
  /// [pushType] 推送类型
  /// [save] 是否保存消息到本地,默认保存
  void sendMsg(
    String content, {
    String? sessionId,
    String? lastServiceMessageId,
    int? messageId,
    bool save = true,
  });

  ///新增等待回答消息
  Future<MsgInfo?> addWaitAnswerMsg({
    required String sessionId,
    String? serviceMessageId,
    List<String>? serviceNextMessageIds,
  });

  ///删除消息
  Future<void> deleteMsg(MsgInfo messageInfo);

  /// 通过会话id删除
  Future<void> deleteBySessionId(String sessionId);

  ///接收到消息回到
  Future<void> receiveMsgAnswer({
    required String sessionId,
    required String serviceMessageId,
    required MsgRpyRspAnswer answer,
  });

  ///插入或者更新消息状态
  Future<MsgInfo?> insertOrUpdateMsg(
    String content, {
    String? sessionId,
    String? userId,
    int? msgId,
    String? sendFailReason,
    String? serviceMsgId,
    List<String>? serviceNextMessageIds,
    MsgStatus status = MsgStatus.sended,
    MsgContentType contentType = MsgContentType.text,
    bool isPrivateChat = false,
    bool isCreate = true,
  });
}
